package 算法.A;

import com.sun.source.tree.IfTree;

public class Main {
    //字符串的相加
    public static String addStrings(String num1, String num2) {
        //从最后一位开始计算
        int len1 = num1.length() - 1;
        int len2 = num2.length() - 1;
        int carry = 0;
        StringBuffer str = new StringBuffer();
        while (len1 >= 0 || len2 >= 0) {
            int x = len1 >= 0 ? num1.charAt(len1) - '0' : 0;
            int y = len2 >= 0 ? num2.charAt(len2) - '0' : 0;
            int cur=x+y+carry;  //计算出来x+y+carry
            carry = (cur) / 10;
            int res = (cur) % 10;
            str.append(res);
            len2--;
            len1--;
        }
        if (carry > 0) {
              str.append(carry);
        }
        return str.reverse().toString();
    }
//    public int[][] generateMatrix(int n) {
//        //生成一个1-n的所有数字  按照一定的规则进行排列?
//
//    }
    public static void main(String[] args) {
        System.out.println(addStrings("456","77"));
    }
}
